package client;

import java.awt.BorderLayout;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import jsonParser.ExportCSV;
import model.SensorController;

public class IRIclient {
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from
     * the event dispatch thread.
     */
	public static JFrame frame;
	
    private static void createAndShowGUI() {
        //set system look and feel
    	try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (UnsupportedLookAndFeelException e) {
			System.err.println("System Look and feel not supported");
		} catch (ClassNotFoundException e) {
			System.err.println("No such Look and Feel");
		} catch (InstantiationException e) {
			System.err.println("Nu instantiation of system look and feel");
		} catch (IllegalAccessException e) {
			System.err.println("Illegal acces to Look and Feel");
		}
    	
    	//Create and set up the window.
        frame = new JFrame("IRI Client Application");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        //Add content to the window.
        frame.add(Tabs.getInstance(), BorderLayout.CENTER);
        
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }
    
    public static void main(String[] args) {
    	//create the sensorcontroller and start its thread
    	SensorController sens = SensorController.getInstance();
        //Schedule a job for the event dispatch thread:
        //creating and showing this application's GUI.
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                //Turn off metal's use of bold fonts
				UIManager.put("swing.boldMetal", Boolean.FALSE);
				createAndShowGUI();
            }
        });

        new Thread(new Runnable() {
			@Override
			public void run() {
		        try {
					new ExportCSV().generateAlarmCsv();
				} catch (IOException e) {
					e.printStackTrace();
				} // Class for logging
			}
		}).start();
        
        new Thread(new Runnable() {
			@Override
			public void run() {
		        try {
					new ExportCSV().generateCsvFile();
				} catch (IOException e) {
					e.printStackTrace();
				} // Class for logging
			}
		}).start();
    }

}
